package com.cskaoyan.util;

import com.cskaoyan.model.vo.StorageVO;
import org.springframework.web.multipart.MultipartFile;

import java.util.Date;
import java.util.UUID;

/**
 * @program: mall38
 * @description: 获取文件的key、name、type、size、url、updateTime
 * @author: Lexis
 * @create: 2022-05-05 20:25
 **/

public class FileProcessUtil {
    public static StorageVO getFileInfo(MultipartFile myfile){
        StorageVO storageVO = new StorageVO();
        String filename = myfile.getOriginalFilename();
        storageVO.setName(filename);
        filename = UUID.randomUUID() + "-" + filename;
        storageVO.setKey(filename);
        storageVO.setSize(myfile.getSize());
        storageVO.setUpdateTime(new Date());
        storageVO.setType(myfile.getContentType());
        storageVO.setUrl("http://localhost:8083/image/"+ filename);
        return storageVO;
    }
}
